package com.dreamoo.service.strategy.image;

import com.dreamoo.common.enums.FileStorageEnum;
import com.dreamoo.common.exception.BusinessException;
import com.dreamoo.common.util.AliOssUtil;
import dev.langchain4j.data.image.Image;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.net.URI;

/**
 * @author 山顶洞人郑某
 * @className OssFileStorage.java 阿里云存储
 * @date 2025 05 15
 */
@Component
@Slf4j
public class OssFileStorage implements FileStoragStrategy{


    /**
     * 保存文件到OSS
     * @param image 图片文件
     * @param mimeType 图片类型
     * @return 图片url
     */
    @Override
    public String saveFile(Image image, String mimeType) {

        URI url = image.url();
        try {
            return AliOssUtil.upload(url,"jpg");
        } catch (IOException e) {

            throw new BusinessException("阿里云 图片上传失败");
        }
    }

    @Override
    public FileStorageEnum getType() {
        return FileStorageEnum.OSS;
    }
}
